﻿Public Class fReconstruyePeriodo
    Dim WithEvents ReconInven As lbGlobalcom.cReconstruyeInventarios
    Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click
        Me.Close()
    End Sub

    Private Sub btnProcesa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcesa.Click
        Try
            Dim per As lbGlobalcom.cPeriodos = New lbGlobalcom.cPeriodos(txtDesdePer.Text)
            Dim Salir As Boolean = False
            While Not Salir
                ReconInven = New lbGlobalcom.cReconstruyeInventarios(per.IDPERIODO)
                ReconInven.Reconstruye()
                ReconInven = Nothing
                If per.ESTADO = 3 Then
                    Dim CierrPer As New lbGlobalcom.cCierrePeriodo(per.IDPERIODO)
                    CierrPer = Nothing
                ElseIf per.ESTADO = 2 Then
                    Salir = True
                Else
                    per.NextPeriodo()
                End If
            End While
            MessageBox.Show("Se reconstruyerón periodos con exito", "Reconstruye Periodos", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub fReconstruyePeriodo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim Per As lbGlobalcom.cPeriodos = New lbGlobalcom.cPeriodos()
            txtDesdePer.Text = Per.IDPERIODO
            txtHastaPer.Text = Per.IDPERIODO
            Per = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ReconInven_Estado(ByVal txtEstado As String) Handles ReconInven.Estado
        Try
            lbEstado.Text = txtEstado
            Me.Refresh()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class